/**
 * Copyright (C) 2009-2012, KingHool.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses.
 */
package com.kinghool.smodel.query;

import java.util.List;

import com.kinghool.ebos.commons.utils.Utils;
import com.kinghool.smodel.IModel;

/**
 * 
 * @Author Allen Deng(dengtailin@gmail.com) 
 */
public class Query { 

	private List<IExpression> expressions = Utils.newList();
	
	public static Query valueOf(String queryExp) {
		Query criteria = new Query();
		criteria.addExpression(PropertyExpression.valueOf(queryExp));
		return criteria;
	}
	
	public void addExpression(IExpression expression) {
		expressions.add(expression);
	}
	
	public void removeExpression(IExpression IExpression) {
		if (expressions.contains(IExpression)) {
			expressions.remove(IExpression);
		} 
	}
	
	public boolean isMatched(IModel model) {
		for (IExpression IExpression : expressions) {
			if (! IExpression.isMatched(model)) {
				return false;
			}
		}
		
		return true;
	}
}
